$(function () {
    $("#tableId").html("");
    $.ajax({
        url: "../findAllTable.do",
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                var state = data[i].tableState;
                var id1 = data[i].tableId;
                if (state === '待结') {
                    $("#tableId").append('<li><a href="javascript:void(0)" onclick="occupy()" aria-disabled="true" class="service"><p class="use_txt">在用</p></a><p class="d_num" name="zhuohao">' + id1 + '</p></li>')
                } else {
                    $("#tableId").append('<li><a href="javascript:void(0)" onclick = "show1(\'' + id1 + '\')" class="unused"><p class="use_txt">空台<span class="p_num">8</span>位</p></a><p class="d_num">' + id1 + '</p></li>')
                }
            }
        },
        dataType: "json",
        error: function () {
            alert("系统出错");
        },
        async: false
    });

})

function cancel() {
    document.getElementById('open').style.display = 'none';
    document.getElementById('operate').style.display = 'none'
}

function occupy() {
    alert("请选择空闲桌")
}

var as;

function show1(id) {
    document.getElementById('open').style.display = 'block';
    document.getElementById('operate').style.display = 'block';
    $("#span1").html(id);
    as = id;
}

function confirmOrder() {
    var people = $("#selectNumber").val();
    $.ajax({
        url: "../orderTable.do",
        data: {
            "tableNum": as,
            "people": people
        },
        success: function (data) {
            window.location.href = "The menu order.html";
        },
        dataType: "json",
        error: function () {
            alert("系统出错");
        }
    })
}